﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmetic.DataEntity;

namespace Cosmetic.Logic
{
    public class AdManager : LogicBase
    {
        /// <summary>
        /// Insert a new Ad into database
        /// </summary>
        /// <param name="anAdvertising">new Ad</param>
        public void Insert(Advertising anAdvertising)
        {
            m_CosmeticDC.Advertisings.InsertOnSubmit(anAdvertising);
            m_CosmeticDC.SubmitChanges();
        }

        /// <summary>
        /// Delete Ad
        /// </summary>
        /// <param name="anAdvertising">The Ad want delete</param>
        public void Delete(Advertising anAdvertising)
        {
            m_CosmeticDC.Advertisings.DeleteOnSubmit(anAdvertising);
            m_CosmeticDC.SubmitChanges();
        }




        /// <summary>
        /// Get Advertising by Ad Id
        /// </summary>
        /// <param name="anAdId">Ad Id</param>
        /// <returns>Advertising</returns>
        public Advertising GetById(Guid anAdId)
        {
            return m_CosmeticDC.Advertisings.SingleOrDefault(theAd => theAd.AdId == anAdId);
        }

        /// <summary>
        /// get Advertising by page name
        /// </summary>
        /// <param name="aPage">the page name</param>
        /// <returns>Advertising list</returns>
        public List<Advertising> GetByPage(string aPage)
        {
            return (from theAd in m_CosmeticDC.Advertisings
                    where theAd.Page.Equals(aPage)
                    select theAd).ToList();
        }

    }
}
